package com.lib.handler;

import com.lib.builder.TextBuilder;
import com.lib.service.BaseWxService;
import me.chanjar.weixin.common.api.WxConsts;
import me.chanjar.weixin.common.exception.WxErrorException;
import me.chanjar.weixin.common.session.WxSessionManager;
import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.bean.message.WxMpXmlMessage;
import me.chanjar.weixin.mp.bean.message.WxMpXmlOutMessage;
import me.chanjar.weixin.mp.bean.result.WxMpUser;

import java.util.Map;

/**
 * 
 * @author Binary Wang
 *
 */
public abstract class SubscribeHandler extends AbstractHandler {

  @Override
  public abstract WxMpXmlOutMessage handle(WxMpXmlMessage wxMessage, Map<String, Object> context, WxMpService wxMpService,
      WxSessionManager sessionManager) throws WxErrorException;
  /**
   * 处理特殊请求，比如如果是扫码进来的，可以做相应处理
   */
  protected abstract WxMpXmlOutMessage handleSpecial(WxMpXmlMessage wxMessage) throws Exception;

  protected abstract WxMpXmlOutMessage handleNormal(WxMpXmlMessage wxMessage) throws Exception;

  protected WxMpXmlOutMessage getResponseMessage(WxMpXmlMessage wxMessage){
      WxMpXmlOutMessage responseResult = null;

      //特殊扫码关注进来的
      try {
        responseResult = this.handleSpecial(wxMessage);
        if (responseResult != null) {
          return responseResult;
        }
      } catch (Exception e) {
        this.logger.error(e.getMessage(), e);
      }


      //普通关注进来的
      try {
        return this.handleNormal(wxMessage);
      } catch (Exception e) {
        this.logger.error(e.getMessage(), e);
      }
      return null;
  }

}
